#! /usr/bin/env python
# encoding: utf-8
# Thomas Nagy, 2006-2010 (ita)

"""
Add a task generator method that will expand ${} expressons from various
attributes such as includes, target, source, etc
"""

VERSION='0.0.1'
APPNAME='cc_test'

top = '.'
out = 'build'

def options(opt):
	opt.load('compiler_c')

def configure(conf):
	conf.load('compiler_c')

def build(bld):
	bld.env.FOO = '/usr/includes'
	bld.env.MAIN = 'main.c'
	bld(
		features = 'c cprogram',
		source   = '${MAIN}',
		target   = 'app',
		includes = '. ${FOO}')

from waflib import Utils, TaskGen
@TaskGen.feature('*')
@TaskGen.before('process_source', 'process_rule', 'apply_incpaths', 'apply_link')
def transform_strings(self):
	for x in 'includes target source use libpath linkflags'.split():
		val = getattr(self, x, None)
		if val:
			if isinstance(val, str):
				setattr(self, x, Utils.subst_vars(val, self.env))
			elif isinstance(val, list):
				for i in range(len(val)):
					if isinstance(val[i], str):
						val[i] = Utils.subst_vars(val[i], self.env)

